package com.ty.consumer;


import com.ty.dto.Luo;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class TopicConsumer {

    //定义一个队列 持久化 Q1
    @Bean
    public Queue ling1(){
        return QueueBuilder.durable("伶").build();
    }
    @Bean
    public Queue ling2(){
        return QueueBuilder.durable("令").build();
    }
    @Bean
    public Queue ling3(){
        return QueueBuilder.durable("雪").build();
    }

    //定义一个交换机Direct-ex  持久化 Q1
    @Bean
    public TopicExchange exchange(){
        return ExchangeBuilder.topicExchange("Topic-ex").durable( true).build();
    }

    //队列和交换机的绑定关
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(ling1()).to(exchange()).with("ling.*");
    }

    @Bean
    public Binding binding2(){
        return BindingBuilder.bind(ling2()).to(exchange()).with("l.*");
    }

    @Bean
    public Binding binding3(){
        return BindingBuilder.bind(ling3()).to(exchange()).with("#");
    }

    @RabbitListener(queues = "伶")
    public void consumer1(Luo msg){
        System.out.println("伶喜欢听的是："+msg);
    }

    @RabbitListener(queues = "令")
    public void consumer2(Luo msg){
        System.out.println("令喜欢听的是："+msg);
    }
    @RabbitListener(queues = "雪")
    public void consumer3(Luo msg){
        System.out.println("雪喜欢听的是："+msg);
    }


}
